/*
  Copyright � 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  ThanhNam ERP Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using VINETLIFE.DO;
using System.Collections.Generic;
/// <summary>
/// Summary description for cmsProductLocationDAL
/// </summary>
namespace VINETLIFE.DAL
{

    public class cmsProductLocationDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public cmsProductLocationDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(cmsProductLocationDO objcmsProductLocationDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductLocation_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@ProductCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductLocationDO.ProductCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LocationCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductLocationDO.LocationCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderId", SqlDbType.Int);
            Sqlparam.Value = objcmsProductLocationDO.OrderId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(cmsProductLocationDO objcmsProductLocationDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductLocation_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@ProductLoctionId", SqlDbType.Int);
            Sqlparam.Value = objcmsProductLocationDO.ProductLoctionId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ProductCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductLocationDO.ProductCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LocationCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductLocationDO.LocationCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderId", SqlDbType.Int);
            Sqlparam.Value = objcmsProductLocationDO.OrderId;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }
        public int UpdateOrInsert(cmsProductLocationDO objcmsProductLocationDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductLocation_UpdateOrInsert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@ProductCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductLocationDO.ProductCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LocationCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductLocationDO.LocationCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderId", SqlDbType.Int);
            Sqlparam.Value = objcmsProductLocationDO.OrderId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;
        }
        public int Delete(cmsProductLocationDO objcmsProductLocationDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductLocation_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ProductLoctionId", SqlDbType.Int);
            Sqlparam.Value = objcmsProductLocationDO.ProductLoctionId;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }
        public int DeleteByProductCode(string productCode)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductLocation_DeleteByProductCode";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ProductCode", SqlDbType.NVarChar);
            Sqlparam.Value = productCode;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }
        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductLocation_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public cmsProductLocationDO Select(cmsProductLocationDO objcmsProductLocationDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductLocation_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ProductLoctionId", SqlDbType.Int);
            Sqlparam.Value = objcmsProductLocationDO.ProductLoctionId;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["ProductLoctionId"]))
                    objcmsProductLocationDO.ProductLoctionId = Convert.ToInt32(dr["ProductLoctionId"]);
                if (!Convert.IsDBNull(dr["ProductCode"]))
                    objcmsProductLocationDO.ProductCode = Convert.ToString(dr["ProductCode"]);
                if (!Convert.IsDBNull(dr["LocationCode"]))
                    objcmsProductLocationDO.LocationCode = Convert.ToString(dr["LocationCode"]);
                if (!Convert.IsDBNull(dr["OrderId"]))
                    objcmsProductLocationDO.OrderId = Convert.ToInt32(dr["OrderId"]);

            }
            return objcmsProductLocationDO;
        }

        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductLocation_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrcmsProductLocationDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    cmsProductLocationDO objcmsProductLocationDO = new cmsProductLocationDO();
                    if (!Convert.IsDBNull(dr["ProductLoctionId"]))
                        objcmsProductLocationDO.ProductLoctionId = Convert.ToInt32(dr["ProductLoctionId"]);
                    if (!Convert.IsDBNull(dr["ProductCode"]))
                        objcmsProductLocationDO.ProductCode = Convert.ToString(dr["ProductCode"]);
                    if (!Convert.IsDBNull(dr["LocationCode"]))
                        objcmsProductLocationDO.LocationCode = Convert.ToString(dr["LocationCode"]);
                    if (!Convert.IsDBNull(dr["OrderId"]))
                        objcmsProductLocationDO.OrderId = Convert.ToInt32(dr["OrderId"]);
                    arrcmsProductLocationDO.Add(objcmsProductLocationDO);
                }
            }
            return arrcmsProductLocationDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductLocation_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public List<cmsProductLocationDO> SelectListByProductCode(string productCode)
        {
            List<cmsProductLocationDO> lstProLo = new List<cmsProductLocationDO>();
            


            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductLocation_GetByProductCode";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@ProductCode", SqlDbType.NVarChar);
            Sqlparam.Value = productCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    cmsProductLocationDO objcmsProductLocationDO = new cmsProductLocationDO();
                    dr = ds.Tables[0].Rows[i];
                    if (!Convert.IsDBNull(dr["ProductLoctionId"]))
                        objcmsProductLocationDO.ProductLoctionId = Convert.ToInt32(dr["ProductLoctionId"]);
                    if (!Convert.IsDBNull(dr["ProductCode"]))
                        objcmsProductLocationDO.ProductCode = Convert.ToString(dr["ProductCode"]);
                    if (!Convert.IsDBNull(dr["LocationCode"]))
                        objcmsProductLocationDO.LocationCode = Convert.ToString(dr["LocationCode"]);
                    if (!Convert.IsDBNull(dr["OrderId"]))
                        objcmsProductLocationDO.OrderId = Convert.ToInt32(dr["OrderId"]);
                    
                    lstProLo.Add(objcmsProductLocationDO);
                }
            }
            return lstProLo;
        }
        public DataTable SelectByProductCode(string productCode)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductLocation_GetByProductCode";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ProductCode", SqlDbType.NVarChar);
            Sqlparam.Value = productCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }


        #endregion

    }

}
